<?php
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$detail			= $_POST['detail'];
		$keyword		= keyword($detail);
		$status			= $_POST['status']=='publish' ? '1': '0';
		$ip				= getUserIP();

		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/promotion/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_basename = basename($upload_fullpath);
		}

		$upload_fieldname	= 'image';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/promotion/'.md5('thumb'.time()). $upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_image = basename($upload_fullpath);
		}

		$sql = "INSERT INTO `tbl_promotion` (`content_id`, `title`, `detail`, `keyword`, `thumb`, `image`, `ip`, `date`, `status`) VALUES ('', '$title', '$detail', '$keyword', '$upload_basename', '$upload_image', '$ip', NOW(), '$status');";
		mysql_query($sql);
		redirect('../');
		exit;
	}
 
	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
 	$ckeditor->config['toolbar']	= 'Basic';

	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$detailHTML = $ckeditor->editor('detail');
?>